﻿

using Knight.Models.Base;
using Knight.Models.Entity;
using Knlght.Data;
using Knlght.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knight.Models.Services
{
    public class SettingService : ServiceBase
    {
        public ActionResponse SaveSetting(IEnumerable<Setting> settings)
        {
            return doAction(() =>
            {
                var db = new RepositoryBase<DataContext>();
                foreach (var setting in settings)
                {
                    //先删除，再添加
                    db.Remove<Setting>(o => o.Key == setting.Key);
                    db.Insert(setting);
                }
                return true;
            });
        }

        public ListResponse<Setting> GetSettingsBy(string group)
        {
            return GetList<Setting>(() =>
            {
                var db = new RepositoryBase<DataContext>();
                var query = new QueryRequest<Setting>();
                query.Add(o => o.Group == group);
                return db.GetList(query);
            });
        }
    }
}
